﻿Imports Negocio
Public Class frmDistribucion

    Dim servicio1 As New TurnoNegocio
    Dim servicio2 As New VehiculoNegocio
    Dim servicio3 As New PedidoNegocio

    Dim report As New crDistribucion

    Sub cargarVehiculos()
        Dim ds As DataSet = servicio2.listarVehiculos()
        With cboVehiculo
            .DataSource = ds.Tables(0)
            .ValueMember = "VEH_Codigo"
            .DisplayMember = "VEH_Placa"
        End With
    End Sub

    Sub cargarTurnos()
        Dim ds As DataSet = servicio1.obtenerTurnos(Date.Now.ToString("HH:mm:ss"))
        With cboTurno
            .DataSource = ds.Tables(0)
            .ValueMember = "TUR_Codigo"
            .DisplayMember = "TUR_Descripcion"
        End With
    End Sub

    Sub iniciar()
        cargarTurnos()
        cargarVehiculos()
    End Sub

    Private Sub frmDistribucion_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        iniciar()
    End Sub

    Sub filtrar()
        Dim data As New DataDis

        Dim ds As DataSet = servicio3.obtenerDiarioDistribucion(cboTurno.SelectedValue.ToString, dtpFecha.Text.Trim, cboVehiculo.SelectedValue.ToString)

        For i = 0 To ds.Tables(0).Rows.Count - 1
            data.Tables("Distribucion").Rows.Add(ds.Tables(0).Rows(i)("clienteAgencia").ToString.Trim, ds.Tables(0).Rows(i)("direccion").ToString.Trim,
                                                 ds.Tables(0).Rows(i)("guiaFactura").ToString.Trim, ds.Tables(0).Rows(i)("bultosEnvases").ToString.Trim,
                                                 ds.Tables(0).Rows(i)("condVenta").ToString.Trim, ds.Tables(0).Rows(i)("monedaAbrev").ToString.Trim,
                                                 ds.Tables(0).Rows(i)("totalCobrar").ToString.Trim, ds.Tables(0).Rows(i)("pedido").ToString.Trim)
        Next

        report.SetDataSource(data)
        Me.crvDistribucion.ReportSource = report
    End Sub

    Private Sub btnFiltrar_Click(sender As System.Object, e As System.EventArgs) Handles btnFiltrar.Click
        filtrar()
    End Sub

End Class